package com.shuai.controller;

import com.shuai.model.vo.ProjectVO;
import com.shuai.model.vo.SubProjectVO;
import com.shuai.service.SubProjectService;
import com.shuai.utils.R;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Map;

@RestController
@RequestMapping(value = "/subProject")
@Tag(name = "子项目管理")
public class SubProjectController {

    @Autowired
    private SubProjectService subProjectService;

    /**
     * subProjectName
     * pageIndex
     * pageSize
     * projectId
     *
     * @param params
     * @return
     */
    @PostMapping(value = "/searchSubProject")
    public R searchSubProject(@RequestBody Map<String, Object> params) {
        return this.subProjectService.searchSubProject(params);
    }

    /**
     * 查询当前项目下所有子项目的所占比重
     * params : projectId
     */
    @PostMapping(value = "/selectPropAllSubProject")
    public R selectPropAllSubProject(@RequestBody ProjectVO vo) {
        return this.subProjectService.selectPropAllSubProject(vo);
    }

    /**
     * 添加子项目
     * projectId
     * subProjectName
     * managerId
     * prop 子项目所占比重
     * timeLimit 工时
     * startTime
     * endTime
     */

    @PostMapping(value = "/addSubProject")
    public R addSubProject(@RequestBody SubProjectVO vo) {
        return this.subProjectService.addSubProject(vo);
    }

    /**
     * subProjectName
     * managerId
     * timeLimit
     * startTime
     * endTime
     * prop
     * subprojectId
     *
     * @param vo
     * @return
     */
    @PostMapping(value = "updateSub")
    public R updateSub(@RequestBody SubProjectVO vo) {
        return this.subProjectService.updateSubProject(vo);
    }

    @PostMapping(value = "delSub")
    public R delSub(@RequestBody SubProjectVO vo) {
        return this.subProjectService.delSub(vo);
    }
}